package cn.dengta.webapp.trade.dto;

import cn.dengta.context.rpc.CachedConfig;
import cn.dengta.context.rpc.CachedConfigManager;
import cn.dengta.webapp.trade.dto.common.IntimacyAwardConfig;
import cn.dengta.webapp.trade.dto.common.RecommendWhite;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ShareCommonConfig {

	/** 自动加入、退出推荐白名单规则 */
	private RecommendWhite white;
	/** 亲密度等级奖励配置 */
	private IntimacyAwardConfig award;

	public static ShareCommonConfig getDefault() {
		final ShareCommonConfig config = new ShareCommonConfig();
		config.setWhite(new RecommendWhite());
		config.setAward(new IntimacyAwardConfig());
		return config;
	}

	public static CachedConfig<ShareCommonConfig> cache() {
		return ShareCommonConfig.InstanceHolder.instance;
	}

	public static RecommendWhite buildWhite() {
		return cache().get().getWhite();
	}

	public static IntimacyAwardConfig buildAward() {
		return cache().get().getAward() == null ? new IntimacyAwardConfig() : cache().get().getAward();
	}

	public IntimacyAwardConfig getAward() {
		if (award == null) {
			award = new IntimacyAwardConfig();
		}
		return award;
	}

	private static final class InstanceHolder {

		static final CachedConfig<ShareCommonConfig> instance = CachedConfigManager.create(ShareCommonConfig.class, ShareCommonConfig::getDefault);

	}

}
